# Contributor: Hoang Nguyen <folliekazetani@protonmail.com>
# Contributor: Tuan Hoang <tmhoang@linux.ibm.com>
# Maintainer: Tuan Hoang <tmhoang@linux.ibm.com>
pkgname=yq-go
_projname=yq
pkgver=4.43.1
pkgrel=1
pkgdesc="Portable command-line YAML processor written in Go"
url="https://github.com/mikefarah/yq"
arch="all"
license="MIT"
makedepends="go"
checkdepends="bash tzdata"
replaces="yq~=4.0"  # backward compatibility (Alpine <3.20)
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/mikefarah/yq/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_projname-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v -o yq

	./yq shell-completion bash > yq.bash
	./yq shell-completion zsh > yq.zsh
	./yq shell-completion fish > yq.fish
}

check() {
	go test ./...

	# Yanked from scripts/acceptance.sh
	for test in acceptance_tests/*.sh; do
		echo "--------------------------------------------------------------"
		echo "$test"
		echo "--------------------------------------------------------------"
		bash "$test"
	done
}

package() {
	install -Dm755 yq "$pkgdir"/usr/bin/yq

	install -Dm644 yq.bash \
		"$pkgdir"/usr/share/bash-completion/completions/yq
	install -Dm644 yq.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_yq
	install -Dm644 yq.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/yq.fish
}

sha512sums="
a3bb594421811db613118af5ba002e08ccb4b76a63ddf428bbdd4926cf8614217d67f47bfa4ad2c87361a96ade1841fde656fcf9ed700a8994333d61b9a80a8d  yq-go-4.43.1.tar.gz
"
